package com.easygem.controller.front;

import com.easygem.common.annotation.ControllerEndpoint;
import com.easygem.common.error.SystemException;
import com.easygem.common.model.system.User;
import com.easygem.common.response.ResponseBean;
import com.easygem.common.vo.front.SeatVO;
import com.easygem.common.vo.system.DepartmentVO;
import com.easygem.common.vo.system.PageVO;
import com.easygem.front.service.SeatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 廖思炜
 * @version 1.0
 * @className SeatController
 * @Description TODO 坐席管理控制层
 * @date 2025/3/25 9:14
 */
@Api(tags = "坐席设置管理")
@RestController
@RequestMapping("/comcentre/seats")
public class SeatController {
    @Autowired
    private SeatService seatService;

    @ApiOperation(value = "得到一定查询条件下的所有坐席列表(坐席设置特供版)")
    @GetMapping("/getAllSeats")
    public ResponseBean getUsersList(SeatVO seatVO) throws SystemException {
        List<SeatVO> list = seatService.getAllSeatVO(seatVO);
        return ResponseBean.success(list);
    }
    @ApiOperation(value = "用户坐席列表", notes = "多条件查询用户坐席列表")
    @GetMapping("/findList")
    public ResponseBean<PageVO<User>> findList(
            @RequestParam("pageNum") Integer pageNum
            , @RequestParam("pageSize") Integer pageSize
            , SeatVO seatVO
    ) throws SystemException {
        PageVO<User> list = seatService.findList(pageNum, pageSize, seatVO);
        return ResponseBean.success(list);
    }

    @ApiOperation(value = "得到所有部门", notes = "多条件查询用户坐席列表")
    @GetMapping("/findDeptList")
    public ResponseBean<List<DepartmentVO>> findDepartmentList() {
        List<DepartmentVO> list=seatService.getAllDeptList();
        if(list==null){
            return ResponseBean.success(null);
        }else {
            return ResponseBean.success(list);
        }
    }

    @ControllerEndpoint(exceptionMessage = "修改坐席状态失败", operation = "修改坐席状态")
    @ApiOperation(value = "设置坐席状态", notes = "修改坐席状态")
    @RequiresPermissions({"users:editStatus"})
    @PutMapping("/setSeatStatus")
    public ResponseBean setSeatStatus(@RequestBody SeatVO seatVO) throws SystemException {
        Integer flag = seatService.setSeatStatus(seatVO);
        if (flag > 0) {
            return ResponseBean.success("success");
        } else {
            return ResponseBean.error("error");
        }
    }

    @ApiOperation(value = "得到坐席最大数量与当前已使用的坐席量", notes = "得到坐席最大数量与当前已使用的坐席量")
    @GetMapping("/getSeatsNumber")
    public ResponseBean<Map<String,Object>> showSeatsCount(@RequestParam("accountName") String accountName){
        System.out.println("::::::::::::::::::"+accountName);
        Map<String,Object> list=seatService.selectSeatsCount(accountName);
        return ResponseBean.success(list);
    }

    @ApiOperation(value = "绑定手机号码", notes = "验证验证码绑定手机号码，之后需要验证手机号验证码")
    @RequiresPermissions({"users:bindPhone"})
    @PutMapping("/bindPhone")
    public ResponseBean bindPhone(
            @RequestBody SeatVO seatVO) throws SystemException
    {
        Integer flag= seatService.bindPhone(seatVO);
        if (flag>0){
            System.out.println("绑定成功");
        }
        return ResponseBean.success(flag);
    }

    @ApiOperation(value = "得到已绑定的手机号码")
    @GetMapping("/getBindPhone")
    public ResponseBean getBindPhone() {
        String phone = seatService.getBindPhone();
        return ResponseBean.success(phone);
    }
    @ApiOperation(value = "解除已绑定的手机号码")
    @RequiresPermissions({"users:unBindPhone"})
    @GetMapping("/unBindPhone")
    public ResponseBean unBindPhone() throws SystemException {
        Integer flag = seatService.unBindingPhone();
        if (flag > 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("error");
        }
    }

}
